package com.etc.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.etc.pojo.EmpPo;

@RestController
public class Ajax2Controller {

	@PostMapping("searchajax.action")
	public List<EmpPo> search(EmpPo po, Model model) {
		
		System.out.println(po.getEname());
		System.out.println(po.getJob());
		
		List<EmpPo> elist = new ArrayList<>();
		elist.add(new EmpPo(111, "tom", "经理"));
		elist.add(new EmpPo(112, "jeery", "财务"));
		elist.add(new EmpPo(113, "jhone", "财务"));
		
		model.addAttribute("elist", elist);
		
		
		return elist; // ===> json对象
	}
	
	@PostMapping("searchajax1.action")
	public List<EmpPo> search1(@RequestBody() EmpPo po, Model model) {
		
		System.out.println(po.getEname());
		System.out.println(po.getJob());
		
		List<EmpPo> elist = new ArrayList<>();
		elist.add(new EmpPo(111, "tom", "经理"));
		elist.add(new EmpPo(112, "jeery", "财务"));
		elist.add(new EmpPo(113, "jhone", "财务"));
		
		model.addAttribute("elist", elist);
		
		
		return elist; // ===> json对象
	}
}
